<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

class PermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //权限表
        app()['cache']->forget('spatie.permission.cache');
        $permission = [
          [
              'name'=>'user.lock',
              'cn_name'=> '用户禁用与启用'
          ]  ,
            [
                'name'=>'user.index',
                'cn_name'=>'用户列表'
            ],
            [
                'name'=>'user.show',
                'cn_name'=>'用户详情'
            ]
        ];
        foreach ($permission as $p){
            Permission::create($p);
        }


        //创建用户  并分配权力
        $tourist = ['write.index','write.show','comments.index'];
        $user = ['write.index','write.show','comments.index','comments.store'];
//        $author = ['write.index','write.show','comments.index','write.store','write.update','write.lock'];
//        $role = Role::create(['name'=>'tourist','cn_name'=>'游客']);
//        $role->givePermissionTo($tourist);
        $role = Role::create(['name'=>'user','cn_name'=>'用户']);
        $role->givePermissionTo($user);
//        $role = Role::create(['name'=>'author','cn_name'=>'作者']);
//        $role->givePermissionTo($author);
    }

}
